package logic

import (
	"context"
	"goods/goods"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsListLogic) GoodsList(req *types.GoodsListRequest) (resp *types.Response, err error) {
	goodsList, err := l.svcCtx.GoodsRpc.GoodsList(l.ctx, &goods.GoodsListRequest{GoodsName: req.GoodsName})
	if err != nil {
		return nil, err
	}

	return &types.Response{
		Code:    0,
		Message: "商品列表",
		DAta: map[string]interface{}{
			"list": goodsList.List,
		},
	}, nil
}
